package ch.justdoit.andriodrpncalc.model;

public class PromptNumber extends CalcNumber {

	public PromptNumber(Model _model) {
		super(_model);
	}

	@Override
	public String toString() {
		String result = "";
		if (!empty) {
			if (getExpressionString().equals("")) {
				if (isToBase()) {
					if (model.mSettings.getDisplayBase() == Settings.BASE.DEC) {
						result = Integer.toString(doubleNumber.intValue());
						result = "# " + result + "d";
					} else if (model.mSettings.getDisplayBase() == Settings.BASE.BIN) {
						result = Integer
								.toBinaryString(doubleNumber.intValue());
						result = "# " + result + "b";
					} else if (model.mSettings.getDisplayBase() == Settings.BASE.HEX) {
						result = Integer.toHexString(doubleNumber.intValue());
						result = "# " + result + "h";
					} else if (model.mSettings.getDisplayBase() == Settings.BASE.OCT) {
						result = Integer.toOctalString(doubleNumber.intValue());
						result = "# " + result + "o";
					}
				} else {
					String doubleString = doubleNumber.toString();
					if (model.mSettings.getDigitsAfterPoint() != 0) {
						String v = "";
						String h = "";

						int p = doubleString.indexOf(".");

						v = doubleString.substring(0, p);
						h = doubleString
								.substring(p + 1, doubleString.length());
						if (h.length() < model.mSettings.getDigitsAfterPoint()) {
							for (int i = h.length(); i < model.mSettings
									.getDigitsAfterPoint(); i++) {
								h += "0";
							}
						} else {
							// abschneiden
							h = h.substring(0, model.mSettings
									.getDigitsAfterPoint());
						}

						doubleString = v + "." + h;
					}
					result = doubleString;
				}
			} else {
				result = getExpressionString();
			}
		}
		return result;
	}

}
